//
//  DAPersonalBackBookTableViewCell.m
//  DAKnowledge
//
//  Created by DreamArts on 16/6/8.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAPersonalBackBookTableViewCell.h"
#import "DALabel.h"
#import "DARateView.h"
#import "DAHomePageTimeLineModel.h"
#import "Utility.h"
#import "DAHeader.h"
#import "UIImageView+WebCache.h"
@interface DAPersonalBackBookTableViewCell ()

@property (weak, nonatomic) IBOutlet UILabel *timeLineLabel;
@property (weak, nonatomic) IBOutlet DALabel *timeAndStatusLabel;
@property (weak, nonatomic) IBOutlet UIImageView *bookImageView;
@property (weak, nonatomic) IBOutlet DALabel *bookSourceLabel;
@property (weak, nonatomic) IBOutlet DALabel *bookNameLabel;
@property (weak, nonatomic) IBOutlet UIView *StatusBackView;
@property (weak, nonatomic) IBOutlet UIImageView *statusImage;
@property (weak, nonatomic) IBOutlet DALabel *borrowTimeLabel;
@property (weak, nonatomic) IBOutlet DALabel *rateNumLabel;
@property (weak, nonatomic) IBOutlet DARateView *rateView;
@property (weak, nonatomic) IBOutlet DALabel *rateLabel;
@property (weak, nonatomic) IBOutlet DALabel *rateMessage;


@end

@implementation DAPersonalBackBookTableViewCell

- (void)awakeFromNib {
    // Initialization code
}


- (void)setTimeLineModel:(DAHomePageTimeLineModel *)timeLineModel{
    if (_timeLineModel != timeLineModel) {
        _timeLineModel = timeLineModel;
    }
    NSString *str;
    self.StatusBackView.layer.cornerRadius = 10;
    self.StatusBackView.backgroundColor = [UIColor colorWithHexString:@"#BFBFBF"];
    self.statusImage.image = [UIImage imageNamed:@"book@3x"];
    NSString *back = NSLocalizedString(@"back", nil);
    str = [NSString stringWithFormat:@"%@ %@", timeLineModel.timelineDate, back];
    
    // 时间和类型
    [self.timeAndStatusLabel setText:str fitToContent:YES];
    self.timeAndStatusLabel.textColor = [UIColor colorWithHexString:timeColor];
    self.timeAndStatusLabel.font = [UIFont systemFontOfSize:12];
    // 时间轴
    self.timeLineLabel.backgroundColor = [UIColor colorWithHexString:timeLineColor];
    
    
    UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.bookImageView.frame.size.width, self.bookImageView.frame.size.height)];
    bookCover.backgroundColor = [UIColor supportGreenColor];
    DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
    [bookCoverName setText:timeLineModel.bookName fitToContent:YES];
    [bookCoverName setTextColor:[UIColor whiteColor]];
    bookCoverName.font = [UIFont systemFontOfSize:12];
    bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
    bookCoverName.textAlignment = NSTextAlignmentCenter;
    [bookCover addSubview:bookCoverName];
    
    UIImage *image = [self makeImageWithView:bookCover];
    [self.bookImageView sd_setImageWithURL:[NSURL URLWithString:timeLineModel.bookImage] placeholderImage:image];

    // 图书 图片
   // [self.bookImageView sd_setImageWithURL:[NSURL URLWithString:timeLineModel.bookImage] placeholderImage:[UIImage imageNamed:@"Java.jpg"]];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showBookDetail:)];
    self.bookImageView.userInteractionEnabled = YES;
    [self.bookImageView addGestureRecognizer:tap];
    [self.bookImageView.layer setBorderColor:[UIColor whiteColor].CGColor];
    [self.bookImageView.layer setBorderWidth:3];
    // 图书名
    self.bookNameLabel.textColor = [UIColor colorWithHexString:bookNameColor];
    [self.bookNameLabel setText:timeLineModel.bookName fitToContent:YES];
    self.bookNameLabel.font = [UIFont systemFontOfSize:13];
    self.bookNameLabel.verticalAlignment = VerticalAlignmentTop;
    // 出借人
    NSString *bookSource = NSLocalizedString(@"bookSource", nil);
    NSString *lenderStr = [NSString stringWithFormat:@"%@: %@", bookSource,timeLineModel.bookSource];
    self.bookSourceLabel.textColor = [UIColor colorWithHexString:lenderColor];
    [self.bookSourceLabel setText:lenderStr fitToContent:YES];
    self.bookSourceLabel.font = [UIFont systemFontOfSize:12];
    // 借阅期
    NSString *borrowTime = NSLocalizedString(@"borrowTime", nil);
    NSString *borrowTimeStr = [NSString stringWithFormat:@"%@: %@", borrowTime,timeLineModel.borrowDuration];
    self.borrowTimeLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
    [self.borrowTimeLabel setText:borrowTimeStr fitToContent:YES];
    self.borrowTimeLabel.font = [UIFont systemFontOfSize:12];
    
    // 评分
    NSString *rateStr = [NSString stringWithFormat:@"%@ :", NSLocalizedString(@"rate", nil)];
    [self.rateNumLabel setText:rateStr fitToContent:YES];
    self.rateNumLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];

    NSInteger rate = [[NSString stringWithFormat:@"%@", timeLineModel.rateNum] integerValue];
    // rateView
    [self.rateView rateNum: rate];
    self.rateView.backgroundColor = [UIColor colorWithHexString:backGroundColor];
    // 评价
    NSString *rateMessage = [NSString stringWithFormat:@"%@ :", NSLocalizedString(@"evaluateLabel", nil)];
    [self.rateLabel setText:rateMessage fitToContent:YES];
    self.rateLabel.textColor = [UIColor colorWithHexString:borrowTimeColor];
    
    [self.rateMessage setText:timeLineModel.rateMessage fitToContent:YES];
    self.rateMessage.font = [UIFont systemFontOfSize:12];
    self.rateMessage.textColor = [UIColor colorWithHexString:borrowTimeColor];
    self.rateMessage.verticalAlignment = VerticalAlignmentTop;
    
    if (timeLineModel.rateMessage.length == 0) {
        NSString *nothing = NSLocalizedString(@"Nothing", nil);
        [self.rateMessage setText:nothing fitToContent:YES];
    }

}

- (void)showBookDetail:(UITapGestureRecognizer *)tap{
    [self.delegate personalBackBookClickBookImage:self.timeLineModel.bookID];
}







- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
